package com.suisung.shopsuite.account.controller.front;

import com.alibaba.fastjson.JSON;
import com.qcloud.cos.utils.Md5Utils;
import com.squareup.okhttp.*;
import org.apache.commons.codec.digest.Md5Crypt;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;

public class Test {
    public static void main(String[] args) throws Exception{
//        URL url = new URL("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxac7c6548bb397005&secret=92593495abc5f703ffcea0efeb59b7b0");
//
//        InputStream inputStream = url.openStream();
//        BufferedInputStream inputStreamReader = new BufferedInputStream(inputStream);
//        InputStreamReader reader = new InputStreamReader(inputStreamReader);
//
//
//        char[] bytes = new char[2048];
//        int length = -1;
//
//
//        StringBuilder sx = new StringBuilder();
//        while (-1 != (length = reader.read(bytes))) {
//            String s = new String(bytes, 0, length);
//
//            sx.append(s);
//
//        }
//
//        System.out.println(sx.toString());
//
//         MediaType mediaType
//                = MediaType.parse("application/json; charset=utf-8");
//
//        OkHttpClient client = new OkHttpClient();
//
//        String access_token = JSON.parseObject(sx.toString()).getString("access_token");
//        System.out.println(access_token);
//
//        inputStreamReader.close();
//
//
//        String getwxacodeUrl = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + access_token;
//        RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(new MiniDTO(access_token, "funpackage/questionsWall/questionInfo?question_id=22579")));
//        Request request = new Request.Builder()
//                .url(getwxacodeUrl)
//                .post(body)
//                .build();
//        Response response = client.newCall(request).execute();
//
////        String s = response.body().string();
////        System.out.println(s);
//
//
//        InputStream ist = response.body().byteStream();
//        FileOutputStream fileOutputStream = new FileOutputStream(new File("D:\\workspace\\xxx.png"));
//
//        byte[]  codebyte = new byte[2048];
//        length = -1;
//        while (-1 != (length = ist.read(codebyte))) {
//            fileOutputStream.write(codebyte, 0, length);
//            fileOutputStream.flush();
//        }
//
//        fileOutputStream.close();
//        ist.close();
//
//        String fileName = Md5Utils.md5Hex("12trplkw34765876ddfffdfdfdgjlkdsjglkdsjalkgjri".getBytes());
//        System.out.println(fileName);
//        fileName = fileName.substring(fileName.length() - 12, fileName.length());
//        System.out.println(fileName);
//
//    }
//
//    public static class MiniDTO {
//        private String access_token;
//        private String path;
//
//        public MiniDTO() {}
//
//        public MiniDTO(String access_token, String path) {
//            this.access_token = access_token;
//            this.path = path;
//        }
//
////        public String getAccess_token() {
////            return access_token;
////        }
//
//        public void setAccess_token(String access_token) {
//            this.access_token = access_token;
//        }
//
//        public String getPath() {
//            return path;
//        }
//
//        public void setPath(String path) {
//            this.path = path;
//        }

        String path = "pages/index/index?s";
        System.out.println(path.substring(path.indexOf("?")));
        System.out.println(path.substring(0, path.indexOf("?")));
        if (-1 != path.indexOf("?")) {
            String substring = path.substring(path.indexOf("?") + 1, path.length());
            System.out.println(substring);
        }
    }


}
